package com.springboot.demo.web;

import com.springboot.demo.entity.ReaderFineRecord;
import com.springboot.demo.service.ReaderFineRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author 17069120036-汪轶辉-974319097@qq.com
 * @date 2020/4/22
 */
//@Controller
//public class ReaderFineController {
   // @Autowired
   // private ReaderService readerService;
   // @Autowired
   // private ReaderFineRecordService readerFineRecordService;
   //@RequestMapping("/reader_fine")
   //public String readerFine(String username, Model model){
     //  Reader reader = readerService.getReaderByName(username);
     //model.addAttribute("user",reader);
       // List<ReaderFineRecord> readerFineRecordByPhone = readerFineRecordService.getReaderFineRecordByPhone(reader.getPhone());
       //model.addAttribute("readerFineRecord", readerFineRecordByPhone);
        //return "reader_fine";
   //}
   // @PostMapping("/payfine/{phone}/{rname}/{bookId}/{startTime}/{fine}")
    //public String payFine(@PathVariable("phone") String phone, @PathVariable("rname") String rname, @PathVariable("bookId") long bookId, @PathVariable("startTime") String startTime, @PathVariable("fine") int fine) {
      //  System.out.println("~~~~~~~~~~~~~~~~~~~pay!");
        //readerFineRecordService.payReaderFine(phone, bookId, startTime, fine);
        //return "redirect:/reader_fine?username="+ rname +"&phone=" + phone;
    //}
//}
@Controller
public class ReaderFineController {
    @Autowired
    private ReaderFineRecordService readerFineRecordService;
    @RequestMapping(value = "/reader_fine",method = RequestMethod.POST)
    @ResponseBody
    public List<ReaderFineRecord> reader_borrow(String phone) throws UnsupportedEncodingException {
        List<ReaderFineRecord> list = new ArrayList<>();
        list.addAll(readerFineRecordService.getReaderFineRecordByPhone(phone));
        return list;
    }

   // @PostMapping("/payfine/{phone}/{rname}/{bookId}/{startTime}/{fine}")
    //public String payFine(@PathVariable("phone") String phone, @PathVariable("rname") String rname, @PathVariable("bookId") long bookId, @PathVariable("startTime") String startTime, @PathVariable("fine") int fine) {
      //  System.out.println("~~~~~~~~~~~~~~~~~~~pay!");
        //readerFineRecordService.payReaderFine(phone, bookId, startTime, fine);
        //return "redirect:/reader_fine_record?username="+ rname +"&phone=" + phone;
    //}
}